const app = getApp()
const log =require('../../log.js');
const util=require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    matchName:'',
    matchId:'',
    idcard:'',
    username:'',
    result:0

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log('-----options start------');
    console.log(options);
    console.log('------options end-----');
    var date=util.formatTime(new Date());
    log.info("Time:"+date+",match:match,options:"+JSON.stringify(options));
    log.info("Time:"+date+",match:match,open:"+JSON.stringify(open));
    var matchName = options.matchname;
    var matchId = options.match_id;
    var shared=options.share;
    var from=options.from;
    if(from==undefined){
     this.setData({
       from:0
     })
    }else{
     this.setData({
       from:1
     })
    }
    if(shared==undefined){
       shared=0;
   }else{
      shared=1;
   }
   wx.showShareMenu({
     menus: ['shareAppMessage', 'shareTimeline'],
     success(res) {
       console.log(res)
     },
     fail(e) {
       console.log(e)
     }
   })   
  this.data.matchName=matchName;
  this.data.matchId=matchId;
    var open=wx.getStorageSync('open');
    console.log(open);
    var member_id=open.member_id;
    var id=open.id;
    if(open==undefined ){
 
     wx.navigateTo({
       url: '../index/login',
     })
    }
    if(open==""){
 
     wx.navigateTo({
       url: '../index/index',
     })
    }
   var that = this;
   this.setData({
    matchName:matchName,
    matchId:matchId,
      domain:app.globalData.domain,
      width:app.globalData.windowWidth,
      height:app.globalData.windowHeight,
      statusBarHeight:app.globalData.statusBarHeight,
      navHeight:app.globalData.navHeight,
      marginTop:app.globalData.navTitleTop
  })
  },
  validName:function(e){
    if(e){
      if (!(/^[\u4E00-\u9FA5A-Za-z0-9]+$/.test(e))) {
        return false;
      }else{
        return true;
      }
   }else{
      return false;
   }

  },
  validIdcardNum:function(e){
    if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(e))) {
     return false;
    }else{
      return true;
    }
  },
  idCard(e){
    console.log(e)
    this.setData({
      idcard:e.detail.value
    })
  },
  userName(e){
    console.log(e)
    this.setData({
      username:e.detail.value
    })
  },
  search(){
    
    let that=this;
    let data=this.data;
    var idcard=data.idcard;
    var username=data.username;
    var matchId=data.matchId;
    var open=wx.getStorageSync('open');
    var user_id=open.id;
    console.log(matchId);
    if(this.validName(username)){
      if(this.validIdcardNum(idcard)){
        if(matchId){         
            wx.request({
              url:app.globalData.domain+'/match/match/matchNo',    
              data: {matchId:matchId,username:username,idcard:idcard },
              success: function (res) {
                console.log(res)
                if(res.statusCode==200){
                    that.setData({
                      result:1,
                      matchNo:res.data.matchNo
                    })
                }
              }            
              
            })
            
          
        }else{
          this.showModels('赛事信息不正确');
        }
      }else{
        this.showModels('身份证号码不正确');
      }
    }else{
      this.showModels('姓名没有输入');
    }
    

  },
  goBack(){
    wx.navigateBack();
  },
  showModels:function(msg){
    wx.showModal({
        title: '系统提示',
        content:msg,
        success:function(res){
            return false;
        }
    })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})